package org.ascollada.core.log
{
	import flash.events.EventDispatcher;
	
	import org.ascollada.core.log.events.DaeLogEvent;
	import org.ascollada.core.log.vo.DaeLogVO;
	
	public class DaeLogger extends EventDispatcher
	{	
		public static var instance	:DaeLogger;

		public static function getInstance() : DaeLogger
		{
			if ( instance == null ) 
			{
				instance = new DaeLogger();
				instance.registerLogger( new DaeTraceLogger() );
			}
			return instance;
		}
		
		public function registerLogger( logger:IDaeLogger ) : void
		{
			logger.register( instance );
		}
		
		public static function log(msg:String, object:Object = null, ...arg):void
		{
			var vo : DaeLogVO = new DaeLogVO(DaeLogLevel.LOG, msg, object, arg);
			
			getInstance().dispatchEvent( new DaeLogEvent(vo) );
		}
		
		public static function info(msg:String, object:Object = null, ...arg):void
		{
			var vo : DaeLogVO = new DaeLogVO(DaeLogLevel.INFO, msg, object, arg);
			
			getInstance().dispatchEvent( new DaeLogEvent(vo) );
		}
		
		public static function debug(msg:String, object:Object = null, ...arg):void
		{
			var vo : DaeLogVO = new DaeLogVO(DaeLogLevel.DEBUG, msg, object, arg);
			
			getInstance().dispatchEvent( new DaeLogEvent(vo) );
		}
		
		public static function warning(msg:String, object:Object = null, ...arg):void
		{
			var vo : DaeLogVO = new DaeLogVO(DaeLogLevel.WARNING, msg, object, arg);
			
			getInstance().dispatchEvent( new DaeLogEvent(vo) );	
		}
		
		public static function error(msg:String, object:Object = null, ...arg):void
		{
			var vo : DaeLogVO = new DaeLogVO(DaeLogLevel.ERROR, msg, object, arg);
			
			getInstance().dispatchEvent( new DaeLogEvent(vo) );
		}
		
		public static function fatal(msg:String, object:Object = null, ...arg):void
		{
			var vo : DaeLogVO = new DaeLogVO(DaeLogLevel.FATAL, msg, object, arg);
			
			getInstance().dispatchEvent( new DaeLogEvent(vo) );	
		}
	}
}